#include "Debug.h"
#include "BoundingBox.h"


BoundingBox::BoundingBox(std::vector<MItMeshVertex*> vertices)
{
	leftLine	= -1 * std::numeric_limits<double>::infinity();		//x
	rightLine	= std::numeric_limits<double>::infinity();			//x
	topLine		= std::numeric_limits<double>::infinity() ;			//y
	bottomLine	= -1* std::numeric_limits<double>::infinity();		//y 
	frontLine	= std::numeric_limits<double>::infinity();			//z
	backLine	= -1* std::numeric_limits<double>::infinity();		//z

	for(int i=0; i<vertices.size(); i++)
	{
		while(!vertices.at(i)->isDone())
	    {
			double xPos = vertices.at(i)->position(MSpace::kWorld).x;	
			double yPos = vertices.at(i)->position(MSpace::kWorld).y;
			double zPos = vertices.at(i)->position(MSpace::kWorld).z;
			//cout << xPos << "," << yPos << endl;

			topLine = min(yPos, topLine);
			bottomLine = max(yPos, bottomLine);
			rightLine = min(xPos, rightLine);
			leftLine = max(xPos, leftLine);		
			frontLine = min(zPos, frontLine);
			backLine = max(zPos, backLine);

			vertices.at(i)->next();
		}	
	}

	frontCorner = MPoint(rightLine, topLine, frontLine, 1.0);
	backCorner = MPoint(leftLine, bottomLine, backLine, 1.0);

	//cout << "topLine: " << topLine << endl;
	//cout << "bottomLine: " << bottomLine << endl;
	//cout << "rightLine: " << rightLine << endl;
	//cout << "leftLine: " << leftLine << endl;
	//cout << "frontLine: " << frontLine << endl;
	//cout << "backLine: " << backLine << endl;
}


BoundingBox::~BoundingBox(void)
{
}


